//
//  DiscoverViewController.m
//  TravelFollowYourHeart
//
//  Created by ENERGY on 2017/12/18.
//  Copyright © 2017年 Lwx. All rights reserved.
//

#import "DiscoverViewController.h"
#import "DiscoverTableViewCell.h"

@interface DiscoverViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong)UIView * topView;
@property (nonatomic, strong)UITableView * tableView;
@property (nonatomic, strong)UIView * leftView;
@property (nonatomic, strong)UIView * rightView;

@end

@implementation DiscoverViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.view addSubview:self.topView];
    [self.view addSubview:self.tableView];
    
    
}

- (UIView *)topView{
    if (!_topView) {
        _topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 100 / 2)];
        _topView.backgroundColor = [UIColor whiteColor];
        
        //右按钮
        UIButton * popularityBtn = [[UIButton alloc] init];
        [popularityBtn setTitle:@"人气" forState:UIControlStateNormal];
        popularityBtn.titleLabel.font = [UIFont systemFontOfSize:14.0];
        [popularityBtn setTitleColor:getColor(@"6d6d6d") forState:UIControlStateNormal];
        popularityBtn.frame = CGRectMake(0, 0, SCREEN_WIDTH / 2, _topView.height);
        [_topView addSubview:popularityBtn];
        
        int leftViewX = 38;
        int lineViewW = SCREEN_WIDTH / 2 - 2 * leftViewX;
        int lineViewH = 3;
        int lineViewY = _topView.bottom - 3;
        self.leftView = [[UIView alloc] init];
        self.leftView.backgroundColor = getColor(@"ffbb02");
        self.leftView.frame = CGRectMake(leftViewX, lineViewY, lineViewW, lineViewH);
        [self.topView addSubview:self.leftView];
        
        //左按钮
        UIButton * timeBtn = [[UIButton alloc] init];
        [timeBtn setTitle:@"事件" forState:UIControlStateNormal];
        timeBtn.titleLabel.font = [UIFont systemFontOfSize:14.0];
        [timeBtn setTitleColor:getColor(@"6d6d6d") forState:UIControlStateNormal];
        timeBtn.frame = CGRectMake(SCREEN_WIDTH / 2, 0, SCREEN_WIDTH / 2, _topView.height);
        [_topView addSubview:timeBtn];
        
        self.rightView = [[UIView alloc] init];
        self.rightView.backgroundColor = getColor(@"ffbb02");
        self.rightView.frame = CGRectMake(SCREEN_WIDTH /2 + leftViewX, lineViewY, lineViewW, lineViewH);
        [_topView addSubview:self.rightView];
        
        //中线
        int middleViewY = 9;
        int middleViewH = _topView.height - 2 * middleViewY;
        UIView * middleView = [[UIView alloc] init];
        middleView.backgroundColor = getColor(@"d2d2d2");
        middleView.frame = CGRectMake(SCREEN_WIDTH / 2, middleViewY, 1, middleViewH);
        [_topView addSubview:middleView];
        
    }return _topView;
}

- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, self.topView.height, SCREEN_WIDTH, SCREEN_HEIGHT - 64 - 49 - self.topView.height) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.backgroundColor = getColor(@"e5e5e5");
        _tableView.contentInset = UIEdgeInsetsMake(5, 0, 0, 0);
        
    }return _tableView;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 2;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString * cellID = @"cell";
    [self.tableView registerClass:[DiscoverTableViewCell class] forCellReuseIdentifier:cellID];
    DiscoverTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
    if (!cell) {
        cell = [[DiscoverTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 222 / WIDTH_5S_SCALE;
}

@end
